package com.fll.common;

import lombok.extern.slf4j.Slf4j;
/**
 *
 * 解析工具类
 *
 * @author fanlei
 * @version 1.0
 * @date 2019年01月25日
 */
@Slf4j
public class LangUtil {

    public LangUtil() {
    }

    public static Boolean parseBoolean(Object value) {
        if (value != null) {
            if (value instanceof Boolean) {
                return (Boolean)value;
            }

            if (value instanceof String) {
                return Boolean.valueOf((String)value);
            }
        }

        return null;
    }

    public static boolean parseBoolean(Object value, boolean defaultValue) {
        if (value != null) {
            if (value instanceof Boolean) {
                return (Boolean)value;
            }

            if (value instanceof String) {
                try {
                    return Boolean.valueOf((String)value);
                } catch (Exception var3) {
                    log.warn("parse boolean value({}) failed.", value);
                }
            }
        }

        return defaultValue;
    }

    public static Integer parseInt(Object value) {
        if (value != null) {
            if (value instanceof Integer) {
                return (Integer)value;
            }

            if (value instanceof String) {
                return Integer.valueOf((String)value);
            }
        }

        return null;
    }

    public static Integer parseInt(Object value, Integer defaultValue) {
        if (value != null) {
            if (value instanceof Integer) {
                return (Integer)value;
            }

            if (value instanceof String) {
                try {
                    return Integer.valueOf((String)value);
                } catch (Exception var3) {
                    log.warn("parse Integer value({}) failed.", value);
                }
            }
        }

        return defaultValue;
    }

    public static Long parseLong(Object value) {
        if (value != null) {
            if (value instanceof Long) {
                return (Long)value;
            }

            if (value instanceof String) {
                return Long.valueOf((String)value);
            }
        }

        return null;
    }

    public static Long parseLong(Object value, Long defaultValue) {
        if (value != null) {
            if (value instanceof Long) {
                return (Long)value;
            }

            if (value instanceof String) {
                try {
                    return Long.valueOf((String)value);
                } catch (NumberFormatException var3) {
                    log.warn("parse Long value({}) failed.", value);
                }
            }
        }

        return defaultValue;
    }

    public static Double parseDouble(Object value) {
        if (value != null) {
            if (value instanceof Double) {
                return (Double)value;
            }

            if (value instanceof String) {
                return Double.valueOf((String)value);
            }
        }

        return null;
    }

    public static Double parseDouble(Object value, Double defaultValue) {
        if (value != null) {
            if (value instanceof Double) {
                return (Double)value;
            }

            if (value instanceof String) {
                try {
                    return Double.valueOf((String)value);
                } catch (NumberFormatException var3) {
                    log.warn("parse Double value({}) failed.", value);
                }
            }
        }

        return defaultValue;
    }
}
